package java_thinking.unit_16;

import java.util.Arrays;

/**
 * @Desc:   复制数组用System.arraycopy()要比用for复制快很多
 *          它不会执行自动包装盒自动拆包，两个数组必须具有相同的确切类型
 * @author: cww
 * @DateTime: 2019-04-09 21:26
 */

public class _7_1CopyingArrays {
    public static void main(String[] args) {
        int[] i = new int[7];
        int[] j = new int[10];
        Arrays.fill(i,47);
        Arrays.fill(j,99);
        System.out.println(Arrays.toString(i));
        System.out.println(Arrays.toString(j));
        System.arraycopy(i,0,j,0,i.length);
        System.out.println(Arrays.toString(j));
        int[] k = new int[5];
        Arrays.fill(k,103);
        System.out.println(Arrays.toString(k));
        System.arraycopy(i,0,k,0,k.length);
        System.out.println(Arrays.toString(k));

        BerylliumSphere[] spheres = new BerylliumSphere[10];
        BerylliumSphere[] spheres1 = new BerylliumSphere[10];
        Arrays.fill(spheres,new BerylliumSphere());
        System.out.println(Arrays.toString(spheres));
        System.arraycopy(spheres, 0, spheres1, 0, spheres1.length);
        System.out.println(Arrays.toString(spheres1));
        spheres[1] = spheres[3];
        System.out.println("spheres = " + Arrays.toString(spheres));
        System.out.println("spheres1 = " + Arrays.toString(spheres1));
    }
}
